﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace Zebra.WinFramework
{
    public partial class WarningForm : FormUC
    {
        #region Application Idle Timings

        //Idle Time MUST be greater than Warning Time
        public static TimeSpan IdleTime = new TimeSpan(00, 04, 00); //new TimeSpan(hours, minutes, seconds)
        public static TimeSpan WarningTime = new TimeSpan(00, 03, 00); //new TimeSpan(hours, minutes, seconds)

        private static string CultureInfoField = Thread.CurrentThread.CurrentCulture.Name;
        public static string CultureInfo
        {
            get { return CultureInfoField; }
            set { CultureInfoField = value; }
        }
        #endregion


        #region Properties

        int hours = 0, minutes = 0, seconds = 0;
        double totalSeconds = 0;

        #endregion

        #region Constructor

        /// <summary>
        /// Initializes a new instance of the <see cref="WarningForm"/> class.
        /// </summary>
        /// <remarks>
        /// Author: suresh.katari,   2/4/2010 - 10:22 AM
        /// Modified By: 
        /// </remarks>
        public WarningForm()
        {
            Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(CultureInfo);
            Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(CultureInfo);
            InitializeComponent();
        }

        #endregion Constructor

        #region Events

        /// <summary>
        /// Handles the Click event of the yesButton control. If the user clicks "Yes" button, the warning form will be closed.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// Author: suresh.katari,   2/4/2010 - 10:22 AM
        /// Modified By: 
        /// </remarks>
        private void yesButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        /// <summary>
        /// Handles the Tick event of the timer control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// Author: suresh.katari,   2/4/2010 - 10:20 AM
        /// Modified By: 
        /// </remarks>
        private void timer_Tick(object sender, EventArgs e)
        {
            if (totalSeconds == 0)
            {
                Application.Exit();
            }
            else
            {
                totalSeconds = totalSeconds - 1;
                if (seconds == 0)
                {
                    if (minutes == 0)
                    {
                        hours -= 1;
                        minutes = 59;
                    }
                    else
                    {
                        minutes -= 1;
                    }
                    seconds = 59;
                }
                else
                {
                    seconds -= 1;
                }

                lblTimeLeft.Text = (hours == 0 || hours < 10 ? "0" + hours.ToString() : hours.ToString()) + " Hour(s) " +
                    (minutes == 0 || minutes < 10 ? "0" + minutes.ToString() : minutes.ToString()) + " Minute(s) " +
                    (seconds == 0 || seconds < 10 ? "0" + seconds.ToString() : seconds.ToString()) + " Second(s)";
                lblTimeLeft.Refresh();
            }
        }

        /// <summary>
        /// Handles the Click event of the noButton control. If the user click the "No" button, the application will be closed.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// Author: suresh.katari,   2/4/2010 - 10:19 AM
        /// Modified By: 
        /// </remarks>
        private void noButton_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        /// <summary>
        /// Handles the Load event of the WarningForm control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>
        /// Author: suresh.katari,   2/4/2010 - 10:18 AM
        /// Modified By: 
        /// </remarks>
        private void WarningForm_Load(object sender, EventArgs e)
        {
            SetLocalizedValues();
            totalSeconds = WarningTime.TotalSeconds;
            hours = WarningTime.Hours;
            minutes = WarningTime.Minutes;
            seconds = WarningTime.Seconds;
            lblTimeLeft.Text = (hours == 0 || hours < 10 ? "0" + hours.ToString() : hours.ToString()) + " Hour(s) " +
                   (minutes == 0 || minutes < 10 ? "0" + minutes.ToString() : minutes.ToString()) + " Minute(s) " +
                   (seconds == 0 || seconds < 10 ? "0" + seconds.ToString() : seconds.ToString()) + " Second(s)";
            lblTimeLeft.Refresh();
        }

        #endregion Events

        #region Private Methdos

        /// <summary>
        /// Sets the localized text to all the labels in the form.
        /// </summary>
        /// <remarks>
        /// Author: suresh.katari,   2/4/2010 - 10:18 AM
        /// Modified By: 
        /// </remarks>
        private void SetLocalizedValues()
        {
            //ResourceManager resourceManager = Common.GetResourceManager(Thread.CurrentThread.CurrentCulture.Name);
            //WarningLabel.Text = resourceManager.GetString("FRM_0080");
            //questionLabel.Text = resourceManager.GetString("FRM_0045");
            //yesButton.Text = resourceManager.GetString("FRM_0039");
            //noButton.Text = resourceManager.GetString("FRM_0033");
        }

        #endregion Private Methods
    }
}
